package com.develop.web.in.service;

//不同产品有不同的实现，不同的计算分期的方式

import com.develop.data.base.model.IdSpaceTimeRecord;
import com.develop.data.loan.model.LoanInstallment;
import com.develop.data.loan.repository.LoanContractRepository;
import com.develop.data.loan.repository.LoanInstallmentRepository;
import com.develop.web.in.service.api.LoanInstallmentDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Component("LoanInstallmentJpaService")
public class LoanInstallmentJpaService implements LoanInstallmentDetailService<LoanInstallment,LoanInstallment> {

    @Autowired
    public LoanContractRepository loanContractRepository;

    @Autowired
    public LoanInstallmentRepository loanInstallmentRepository;


    @Override
    public LoanInstallment detail(LoanInstallment item){

        String id = item.getId();
        LocalDateTime nextInstallmentCursor = item.getInstallmentCursor();

        return loanInstallmentRepository.findById(id).orElse(null);

    }


    @Override
    public List<LoanInstallment> batchDetail(List<LoanInstallment> items){

        return loanInstallmentRepository.findAllById(
                items.stream().map(IdSpaceTimeRecord::getId).collect(Collectors.toList())
        );

    }

}
